package com.dews.web.controller.course;

import com.dews.common.annotation.Log;
import com.dews.common.core.controller.BaseController;
import com.dews.common.core.domain.BaseResponse;
import com.dews.common.core.page.TableDataInfo;
import com.dews.common.enums.BusinessType;
import com.dews.common.utils.poi.ExcelUtil;
import com.dews.course.domain.ro.DegreeGradeRo;
import com.dews.course.domain.vo.DegreeGradeVo;
import com.dews.course.service.IDegreeGradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 学业成绩成绩统计Controller
 * 
 * @author qingfeng
 * @date 2025-02-03
 */
@Api(value = "学业成绩成绩统计", tags = {"学业成绩成绩统计" })
@RestController
@RequestMapping("/course/degreeGrade")
public class DegreeGradeController extends BaseController {

    private IDegreeGradeService degreeGradeService;

    @Autowired
    public DegreeGradeController(IDegreeGradeService degreeGradeService) {
        this.degreeGradeService = degreeGradeService;
    }

    @ApiOperation(value = "获取学生的学业成绩")
    @PreAuthorize("@ss.hasPermi('course:degreeGrade:user')")
    @GetMapping("/getUserDegreeGrade")
    public BaseResponse getUserDegreeGrade() {
        DegreeGradeRo degreeGradeRo = degreeGradeService.getUserDegreeGrade();
        return success(degreeGradeRo);
    }

    @ApiOperation(value = "手动触发学位预警")
    @GetMapping("/degreeWarning")
    public BaseResponse degreeWarning() {
        degreeGradeService.degreeWarning();
        return success();
    }




    @ApiOperation(value = "获取学业成绩成绩统计列表")
    @PreAuthorize("@ss.hasPermi('course:degreeGrade:list')")
    @GetMapping("/list")
    public TableDataInfo list(DegreeGradeVo degreeGradeVo) {
        startPage();
        List<DegreeGradeVo> list = degreeGradeService.selectDegreeGradeList(degreeGradeVo);
        return getDataTable(list);
    }

    @ApiOperation(value = "导出学业成绩成绩统计列表")
    @PreAuthorize("@ss.hasPermi('course:degreeGrade:export')")
    @Log(title = "学业成绩成绩统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DegreeGradeVo degreeGradeVo) {
        List<DegreeGradeVo> list = degreeGradeService.selectDegreeGradeList(degreeGradeVo);
        ExcelUtil<DegreeGradeVo> util = new ExcelUtil<DegreeGradeVo>(DegreeGradeVo.class);
        util.exportExcel(response, list, "学业成绩成绩统计数据");
    }

    @ApiOperation(value = "获取学业成绩成绩统计详细信息")
    @PreAuthorize("@ss.hasPermi('course:degreeGrade:query')")
    @GetMapping(value = "/{id}")
    public BaseResponse getInfo(@PathVariable("id") Integer id) {
        return success(degreeGradeService.selectDegreeGradeById(id));
    }

    @ApiOperation(value = "新增学业成绩成绩统计")
    @PreAuthorize("@ss.hasPermi('course:degreeGrade:add')")
    @Log(title = "学业成绩成绩统计", businessType = BusinessType.INSERT)
    @PostMapping
    public BaseResponse add(@RequestBody DegreeGradeVo degreeGradeVo) {
        return toAjax(degreeGradeService.insertDegreeGrade(degreeGradeVo));
    }

    @ApiOperation(value = "修改学业成绩成绩统计")
    @PreAuthorize("@ss.hasPermi('course:degreeGrade:edit')")
    @Log(title = "学业成绩成绩统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public BaseResponse edit(@RequestBody DegreeGradeVo degreeGradeVo) {
        return toAjax(degreeGradeService.updateDegreeGrade(degreeGradeVo));
    }

    @ApiOperation(value = "删除学业成绩成绩统计")
    @PreAuthorize("@ss.hasPermi('course:degreeGrade:remove')")
    @Log(title = "学业成绩成绩统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public BaseResponse remove(@PathVariable List<Integer> ids) {
        return toAjax(degreeGradeService.deleteDegreeGradeByIds(ids));
    }


}
